package com.iven.xie.redis.controller;

import com.iven.xie.redis.beans.Actor;
import com.iven.xie.redis.beans.RedisConfig;
import com.iven.xie.redis.beans.ResObject;
import com.iven.xie.redis.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @author iven.xie
 */
@Api(tags = "服务redis配置信息接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("api/redis/config")
@Slf4j
public class ConfigController {

    @Autowired
    private ConfigService configService;

    @ApiOperation(value = "查询服务redis默认配置", notes = "查询服务redis默认配置")
    @GetMapping(value = "/default")
    public ResObject<RedisConfig> getDefaultConfig() {
        return ResObject.success(configService.getDefaultConfig());
    }

    @ApiOperation(value = "查询服务redis配置列表", notes = "查询服务redis配置列表")
    @GetMapping(value = "/setting/list")
    public ResObject<List<RedisConfig>> getSettingList() {
        return ResObject.success(configService.getSettingList());
    }

    @ApiOperation(value = "添加服务redis配置", notes = "添加服务redis配置")
    @PutMapping(value = "/setting")
    public ResObject<List<RedisConfig>> addSetting(@RequestBody RedisConfig config) throws IOException {
        return ResObject.success(configService.addSetting(config));
    }

}
